# coding:utf-8
'''
Created on 2010-1-1

@author: Jason Green
@author-email: guileen@gmail.com

#sample interceptor
def my_interceptor(method,*args,**kwargs):
    #before
    res = method(*args,**kwargs)
    #after
    return res
    
def my_func():
    ...
my_func = wrap_interceptors(my_func,[my_interceptor])
my_func = wrap_interceptor(my_func,my_interceptor)
'''
def wrap_interceptors(method,interceptors):
    if(isinstance(method,wrap_interceptor)):
        return method
    _method = method
    for interceptor in reversed(interceptors):
        _method= wrap_interceptor(_method,interceptor)
    return _method

class wrap_interceptor(object):
    def __init__(self,method,interceptor):
        self._orign_method = method
        self._interceptor = interceptor
    
    def __call__(self,*args,**kwargs):
        return self._interceptor(self._orign_method,*args,**kwargs)

